import { Vector2 } from "../vector";  
import { CameraEffect } from "./camera-effect";  
import { lerp } from "../utils";  
import { Engine } from "../engine";
  
export class ZoomEffect extends CameraEffect {  
  private startZoom: number = 1;  
  private targetZoom: number = 1;  
  private currentZoom: number = 1;  
  
  constructor(engine: Engine) {
    super(engine);  
  }  
  
  setZoom(targetZoom: number, duration: number = 1000): void {  
    this.startZoom = this.currentZoom;  
    this.targetZoom = targetZoom;  
    this.start(duration);  
  }  
  
  apply(basePos: Vector2): Vector2 {  
    if (this.isActive) {  
      this.currentZoom = lerp(this.startZoom, this.targetZoom, this.progress);  
    }  
  
    // 缩放通过调整相机位置来实现视野变化的效果  
    const canvas = this.engine.canvas_;  
    const centerX = canvas.width / 2;  
    const centerY = canvas.height / 2;  
      
    const scaledOffsetX = (basePos.x - centerX) * (2 - this.currentZoom);  
    const scaledOffsetY = (basePos.y - centerY) * (2 - this.currentZoom);  
  
    return new Vector2(scaledOffsetX + centerX, scaledOffsetY + centerY);  
  }  
  
  getCurrentZoom(): number {  
    return this.currentZoom;  
  }  
}